/**
* Created by admin on 18-3-21.
*/
<template>
  <el-row class="container">
    <el-col :span="28" class="header">
      <el-col :span="10" class="logo">
        <img src="../assets/logo.jpeg" /><span>志愿合大</span>
      </el-col>
      <el-col :span="8" class="userinfo">
        <el-dropdown trigger="click">
          <span class="el-dropdown-link userinfo-inner"><img src="../assets/user.png"/> {{userName}}</span>
          <el-dropdown-menu slot="dropdown" class="menu">
            <el-dropdown-item v-show="false">我的消息</el-dropdown-item>
            <el-dropdown-item @click.native="changePassword">修改密码</el-dropdown-item>
            <el-dropdown-item divided @click.native="deleteUser">用户注销</el-dropdown-item>
            <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-col>
    <el-col :span="24" class="main">
      <aside>
        <el-menu id="menu" theme="dark" :default-active="$route.path" unique-opened router>
          <!-- 路由权限，先写死 -->
          <template v-for="(item,index) in menuListCn ">
            <el-submenu v-if="item.children && item.children.length" :index="index+''">
              <template slot="title"><i class="el-icon-menu"></i>{{item.permissionName}}</template>
              <el-menu-item v-for="(node,i) in item.children" :key="node.permissionUrl" :index="node.permissionUrl"><i class="el-icon-document"></i>{{node.permissionName}}</el-menu-item>
            </el-submenu>
            <el-menu-item v-else :index="item.permissionUrl"><i class="el-icon-document"></i>{{item.permissionName}}</el-menu-item>
          </template>
        </el-menu>
      </aside>
      <section class="content-container">
        <el-col :span="24" class="breadcrumb-container">
          <strong class="title">{{$route.name}}</strong>
          <el-breadcrumb separator="/" class="breadcrumb-inner">
            <el-breadcrumb-item v-for="item in $route.matched" :key="item.name">
              {{ item.name }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </el-col>
        <el-col :span="24" class="content-wrapper">
          <transition>
            <router-view></router-view>
          </transition>
        </el-col>
      </section>
      <!--<ml-change-password ref="changePassword" changeType="2" :uuid="userUuid"></ml-change-password>-->
      <ml-message></ml-message>
    </el-col>
  </el-row>
</template>
<script>
import DataUtil from '../common/dataUtil'
import mlChangePassword from '../components/_changePassword.vue'
import mlMessage from '../components/Message.vue'
export default {
  data() {
    return {
      userName: '',
      menuList: [],
      menuListCn: [{
        permissionName:'个人中心',
        permissionUrl:'/',
        children:[{
          permissionName:'个人信息',
          permissionUrl:'/PersonInfo',
        },{
          permissionName:'空闲课程表',
          permissionUrl:'/FreeSchedule',
        },{
          permissionName:'活动评价',
          permissionUrl:'/ActivityComment',
        },{
          permissionName:'组织中心',
          permissionUrl:'/OrginzeCenter',
        },
          {
            permissionName:'我的组织',
            permissionUrl:'/OrginzerManage',
          }]
      },{
        permissionName:'活动中心',
        permissionUrl:'/',
        children:[{
          permissionName:'培训活动',
          permissionUrl:'/OrginzerTrain',
        },{
          permissionName:'志愿活动',
          permissionUrl:'/VolunteerTrain',
        },{
          permissionName:'募捐活动',
          permissionUrl:'/FundraisingTrain',
        }]
      },{
        permissionName:'时间表',
        permissionUrl:'/',
        children:[{
          permissionName:'空闲用户表',
          permissionUrl:'/FreeUserSchedule',
        }]
      },{
        permissionName:'审核中心',
        permissionUrl:'/',
        children:[{
          permissionName: '资料上传',
          permissionUrl: '/UploadData',
        },{
          permissionName:'材料审核',
          permissionUrl:'/DataCheck',
        }]
      }]
    }
  },
  methods: {
    getMenuList() {

        let userRole = DataUtil.userRole();
        if (userRole == '1') {
          this.menuListCn = [{
            permissionName:'个人中心',
            permissionUrl:'/',
            children:[{
              permissionName:'个人信息',
              permissionUrl:'/PersonInfo',
            },{
              permissionName:'空闲课程表',
              permissionUrl:'/FreeSchedule',
            },{
              permissionName:'活动评价',
              permissionUrl:'/ActivityComment',
            },
              {
                permissionName:'我的组织',
                permissionUrl:'/OrginzerManage',
              }]
          },{
            permissionName:'活动中心',
            permissionUrl:'/',
            children:[{
              permissionName:'培训活动',
              permissionUrl:'/OrginzerTrain',
            },{
              permissionName:'志愿活动',
              permissionUrl:'/VolunteerTrain',
            },{
              permissionName:'募捐活动',
              permissionUrl:'/FundraisingTrain',
            }]
          }]
        } else if (userRole == '2') {

          this.menuListCn = [{
            permissionName:'个人中心',
            permissionUrl:'/',
            children:[{
              permissionName:'组织中心',
              permissionUrl:'/OrginzeCenter',
            }]
          },{
            permissionName:'活动中心',
            permissionUrl:'/',
            children:[{
              permissionName:'培训活动',
              permissionUrl:'/OrginzerTrain',
            },{
              permissionName:'志愿活动',
              permissionUrl:'/VolunteerTrain',
            },{
              permissionName:'募捐活动',
              permissionUrl:'/FundraisingTrain',
            }]
          },{
            permissionName:'时间表',
            permissionUrl:'/',
            children:[{
              permissionName:'空闲用户表',
              permissionUrl:'/FreeUserSchedule',
            }]
          }]
        } else if (userRole == '3') {
          this.menuListCn = [{
            permissionName:'活动中心',
            permissionUrl:'/',
            children:[{
              permissionName:'培训活动',
              permissionUrl:'/OrginzerTrain',
            },{
              permissionName:'志愿活动',
              permissionUrl:'/VolunteerTrain',
            },{
              permissionName:'募捐活动',
              permissionUrl:'/FundraisingTrain',
            }]
          },{
            permissionName:'审核中心',
            permissionUrl:'/',
            children:[{
              permissionName:'材料审核',
              permissionUrl:'/DataCheck',
            }]
          }]
        } else if (userRole == '4') {
          this.menuListCn = [{
            permissionName:'审核中心',
            permissionUrl:'/',
            children:[{
              permissionName: '资料上传',
              permissionUrl: '/UploadData',
            }]
          }]
        }
    },
    changePassword() {
      this.$refs.changePassword.show()
    },
    deleteUser() {
        this.$confirm('确定注销删除该用户吗？','提示',{}).then(() => {
            DataUtil.sid('');
            this.$http.post('user/userDisable',{'id': DataUtil.id()}).then(response => {
                if (response.body.code == 1 ) {
                   this.$router.push('/login');
                 } else {
                    this.$message.error(response.body.message);
                  }
            })
        })
    },
      //退出登录
      logout() {
        this.$confirm('确认退出登录吗?', '提示', {}).then(() => {
          DataUtil.sid('')
          this.$router.push('/login')
        }).catch(() => {

        });
      },
      logoutone() {
        this.$confirm('Apakah Anda yakin keluar dari akun?', 'Pemberitahuan', {}).then(() => {
          DataUtil.sid('')
          this.$router.push('/login')
        }).catch(() => {

        });
      },
      pageInit() {
        this.userName = DataUtil.userName()
        //this.userUuid = DataUtil.uuid()
      },
    },
    mounted() {
      this.pageInit();
      this.getMenuList();
    },
    components: {
      mlChangePassword,
      mlMessage
    }
  }

  </script>
  <style scoped>
  .container {
    position: absolute;
    top: 0px;
    bottom: 0px;
    width: 100%;
  }

  .header {
    height: 60px;
    line-height: 60px;
    background: #1F2D3D;
    color: #c0ccda;
  }

  .logo {
    font-size: 15px;
  }

  .logo img {
    width: 40px;
    float: left;
    margin: 10px 10px 10px 18px;
  }

  .userinfo {
    width: 380px;
    float: right;
    text-align: right;
    padding-right: 35px;
  }

  .userinfo-inner {
    color: #c0ccda;
    cursor: pointer;
  }

  .userinfo-inner img {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    margin: 10px;
    float: right;
  }

  .main {
    background: #324057;
    position: absolute;
    top: 60px;
    bottom: 0px;
    overflow: hidden;
  }

  .main aside {
    width: 200px;
    overflow-y: auto;
    overflow: auto;
    height: 100%;
  }

  .main ul {
    margin-bottom: 50px;
  }

  .el-submenu [class^=fa] {
    vertical-align: baseline;
    margin-right: 10px;
  }

  .el-menu-item [class^=fa] {
    vertical-align: baseline;
    margin-right: 10px;
  }

  .content-container {
    background: #f1f2f7;
    position: absolute;
    right: 0px;
    top: 0px;
    bottom: 0px;
    left: 200px;
    overflow-y: scroll;
    padding: 20px;
  }

  .breadcrumb-container {
    margin-bottom: 15px;
  }

  .title {
    width: 200px;
    float: left;
    color: #475669;
  }

  .breadcrumb-inner {
    float: right;
  }

  .content-wrapper {
    background-color: #fff;
    box-sizing: border-box;
  }
  .languageChange {
    float: right;
    width: 80px;
    height: 40px;
  }
  .languageChange a:hover {
    color: orange;
  }
  .changeLanguage{
    color: #656e73;
    float: right;
  }
  #middle{
    height: 60px;
    line-height: 60px;
    display: inline-block;
    margin: 0 5px;
  }
  .clickOn {
    color: white;
  }
/*  .menu {
    width: 300px;
    }*/
    </style>
